﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;


public partial class AjaxTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      //  List<Movies> movie = GetMovieList("");
    }
    protected void btn_GoTo_Click(object sender, EventArgs e)
    {
        DVDTableAdapters.Movie1TableAdapter ta = new DVDTableAdapters.Movie1TableAdapter();
        GridView1.DataSource = ta.GetMovieByDirector(ddl_Director.SelectedValue);
        GridView1.DataBind();
    }

    [WebMethod]
    public static List<Movies> GetMovieList(string director)
    {
        //A collection of Module objects is declared as 'modules'
        List<Movies> movies = new List<Movies>();      //The Module class can be found in 
        //the App_Code folder
        DVDTableAdapters.Movie1TableAdapter ta = new DVDTableAdapters.Movie1TableAdapter();
        DataTable dt = ta.GetMovieByDirector(director);
        foreach (DataRow row in dt.Rows)
        {
            int MovieID = Convert.ToInt32(row.ItemArray[0].ToString());      //for each row a new Module object
            string Title = row.ItemArray[1].ToString();    //is instantiated and added to the   
            string Description = row.ItemArray[2].ToString();
            int Length = Convert.ToInt32(row.ItemArray[3].ToString());
            string Director = row.ItemArray[4].ToString();
            
            movies.Add(new Movies(MovieID,Title,Description,Length,Director));            //collection   
        }
        return movies;
    } 
}